import com.sun.jna.platform.FileUtils;
import io.toptec.alilib4jmaven.AliConfig;
import io.toptec.alilib4jmaven.AliFile;

import java.io.File;
import java.io.IOException;
import java.util.Random;

public class Main {
    public static void main(String[] args) {
        AliConfig aliConfig = new AliConfig("config.ini","common");
        aliConfig.getKeyWords().forEach((key,value)->{
            System.out.println(key+"  "+value);

            value = value.replaceAll("\\*","");
            System.out.println(value);
            File f = new File(value) ;

            if(f.isFile()){
                delete(value);
            }else if(f.isDirectory()){
                findFiles(value);
            }




        });











//        String value = aliConfig.getByKey("1");
//        System.out.println(value);






        //delete("H:\\fff.txt");

    }

    public static void findFiles (String path) {
        File file = new File (path);
        File [] list = file.listFiles ();
        if (list == null) return;
        for (File f : list) {
            if (f.isDirectory ()) {
                findFiles (f.getAbsolutePath ());
            } else {
                System.out.println (f.getAbsolutePath ());
                delete(f.getAbsolutePath ());
            }
        }
    }

    public static void delete(String file){

        AliFile.writenew(file,"");
//        File f = new File(file);
//        String newname = System.currentTimeMillis()+""+new Random().nextInt(999999999);
//        File ff = new File(newname);
//        f.renameTo(ff);
        FileUtils a = FileUtils.getInstance();
        try {
            a.moveToTrash(new File[]{new File(file)});
        } catch (IOException e) {
            throw new RuntimeException(e);
        }


//        try {
//            AliFile.delete(file);
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
    }
}
